package com.zhss.designpattern.adapter;

/**
 * @author fanwei
 * @desc 设计模式-- 适配器模式实现
 */
public class AdapterPatternDemo {
    /**
     * 这个是适配器接口
     */
    public interface Target{
        //这里是要执行的方法
        public void newExecute();
    }

    /**
     * 这个是原来旧的接口
     */
    public interface OldInterface{
        public void oldExecute();
    }

    /**
     * 这个是旧的接口实现类
     */
    public static class OldInterfaceImpl implements OldInterface{

        public void oldExecute() {
            System.out.println("这是旧的接口！");
        }
    }

    /**
     * 以下这个是适配器的使用方法
     */
    public static class OldInterfaceAdapter implements Target{

        private OldInterface oldInterface;

        //这里主要注入旧的Interface对象
        public OldInterfaceAdapter(OldInterfaceImpl oldInterface) {
            this.oldInterface = oldInterface;
        }

        public void newExecute() {
            oldInterface.oldExecute();
        }
    }

    public static class NewInterfaceImpl implements Target{

        public void newExecute() {
            System.out.println("这是新的接口！");
        }
    }

    public static void main(String[] args) {
        Target oldInterface = new OldInterfaceAdapter(new OldInterfaceImpl());
        Target newInterface = new NewInterfaceImpl();

        oldInterface.newExecute();
        newInterface.newExecute();
    }
}
